#include <boost/python/class.hpp>
#include <boost/python/module.hpp>
#include <boost/python/def.hpp>
#include <boost/python/object.hpp>
#include <boost/python/list.hpp>
#include <vector>

#include "rule.h"
#include "python_converters.h"

using namespace std;
using namespace boost::python;
using namespace fouine;


template<class T, class TContainer>
struct ContainerConverter {
    static void* from_python( PyObject* py_obj);
};

template <class T, class TContainer>
void* ContainerConverter<T,TContainer>::from_python(PyObject* py_obj)
{
        TContainer* pContainer = new TContainer();
        list l = extract<list>(py_obj);
        int n = boost::python::extract<int>(l.attr("__len__")());
		for ( int i = 0; i<n; i++ ){
		    T val = (boost::python::extract<T>(l[i]));
			pContainer->push_back(val);
		}
        return pContainer;
}

void register_converters() { 
	converter::registry::insert( &ContainerConverter<int,vector<int> >::from_python, type_id< vector<int> >() );
	converter::registry::insert( &ContainerConverter<Rule, vector<Rule> >::from_python, type_id< vector<Rule> >() );
}
